<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\UserDangan;
use App\Admin\Repositories\Config;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserDanganController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserDangan('user'), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->model()->orderBy('id', 'desc');
            if(!\Dcat\Admin\Admin::user()->isAdministrator()) {
                $grid->model()->where('user.shop_id', session('shop_id'));
            }
            $grid->column('user.name', '姓名');
            $grid->column('weight');
            $grid->column('height');
            $grid->column('write_date');
            $grid->column('created_at');
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->expand();
                $filter->like('user.name', '姓名')->width(3);
                $filter->like('user.mobile', '手机号')->width(3);
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserDangan(), function (Show $show) {
            $model = $show->model();
            $show->html(view('admin.show.dangan', compact('model')));
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    public function form($id = null)
    {
        return Form::make(new UserDangan('user'), function (Form $form) use ($id) {
            if($id == -1) {
                $form->disableFooter();
                $form->disableHeader();
            }
            $form->column(6, function (Form $form) {
                $form->select('user_id', '用户')->options(function ($id) {
                        $user = \App\Models\User::find($id);
                        if ($user) {
                            return [$user->id => $user->name];
                        }
                })->ajax(admin_url('api/user'))->required()->setLabelClass('col-md-4', true);
                $form->number('height')->setLabelClass('col-md-4', true);
            });
            $form->column(6, function (Form $form) {
                $form->date('write_date', '录入日期')->setLabelClass('col-md-4', true)->default(date('Y-m-d'));
                $form->number('weight')->setLabelClass('col-md-4', true);
            });
            
            $form->column(6, function (Form $form) {
                $form->select('shili_luoyan_right', '裸眼视力')->options(Config::selectOptionsVision())->placeholder('选择右眼裸眼视力')->setFieldClass('col-md-10', true);
                $form->select('shili_jiaozheng_right', '矫正视力')->options(Config::selectOptionsVision())->placeholder('选择右眼矫正视力')->setFieldClass('col-md-10', true);
            });
            $form->column(6, function (Form $form) {
                $form->select('shili_luoyan_left', '')->options(Config::selectOptionsVision())->placeholder('选择左眼裸眼视力')->setFieldClass('col-md-12', true)->setLabelClass('d-none');
                $form->select('shili_jiaozheng_left', '')->options(Config::selectOptionsVision())->placeholder('选择左眼矫正视力')->setFieldClass('col-md-12', true)->setLabelClass('d-none');
            });
            $form->column(4, function (Form $form) {
                $form->select('yanguang_diannao_right.ds', '电脑验光(右) DS')->groups(Config::selectOptionsKeyValues())->config('tags', true)->placeholder('选择右眼电脑验光视力')->setLabelClass('col-md-4', true);
                $form->select('yanguang_diannao_left.ds', '左 DS')->groups(Config::selectOptionsKeyValues())->config('tags', true)->placeholder('选择右眼电脑验光视力')->setLabelClass('col-md-4', true);

                $form->select('jiujing_jiaodu_right.ds', '旧镜焦度计检查（右） DS')->groups(Config::selectOptionsKeyValues())->config('tags', true)->placeholder('选择右眼电脑验光视力')->setLabelClass('col-md-4', true);
                $form->select('jiujing_jiaodu_left.ds', '左 DS')->groups(Config::selectOptionsKeyValues())->config('tags', true)->placeholder('选择右眼电脑验光视力')->setLabelClass('col-md-4', true);

                $form->select('yanguang_zonghe_right.ds', '综合验光(右) DS')->groups(Config::selectOptionsKeyValues())->config('tags', true)->placeholder('选择右眼电脑验光视力')->setLabelClass('col-md-4', true);
                $form->select('yanguang_zonghe_left.ds', '左 DS')->groups(Config::selectOptionsKeyValues())->config('tags', true)->placeholder('选择右眼电脑验光视力')->setLabelClass('col-md-4', true);
            });
            $form->column(4, function (Form $form) {
                $form->select('yanguang_diannao_right.dc', 'DC')->options(Config::selectOptionsKeyValues('cylinder'))->config('tags', true)->setLabelClass('col-md-3', true);
                $form->select('yanguang_diannao_left.dc', 'DC')->options(Config::selectOptionsKeyValues('cylinder'))->config('tags', true)->setLabelClass('col-md-3', true);

                $form->select('jiujing_jiaodu_right.dc', 'DC')->options(Config::selectOptionsKeyValues('cylinder'))->config('tags', true)->setLabelClass('col-md-3', true);
                $form->select('jiujing_jiaodu_left.dc', 'DC')->options(Config::selectOptionsKeyValues('cylinder'))->config('tags', true)->setLabelClass('col-md-3', true);

                $form->select('yanguang_zonghe_right.dc', 'DC')->options(Config::selectOptionsKeyValues('cylinder'))->config('tags', true)->setLabelClass('col-md-3', true);
                $form->select('yanguang_zonghe_left.dc', 'DC')->options(Config::selectOptionsKeyValues('cylinder'))->config('tags', true)->setLabelClass('col-md-3', true);
            });
            $form->column(4, function (Form $form) {
                $form->select('yanguang_diannao_right.a', 'A')->placeholder('电脑验光A轴数据')->options(Config::getSelectOptionsNumber(0, 180))->config('tags', true)->setLabelClass('col-md-3', true);
                $form->select('yanguang_diannao_left.a', 'A')->placeholder('电脑验光A轴数据')->options(Config::getSelectOptionsNumber(0, 180))->config('tags', true)->setLabelClass('col-md-3', true);

                $form->select('jiujing_jiaodu_right.a', 'A')->placeholder('电脑验光A轴数据')->options(Config::getSelectOptionsNumber(0, 180))->config('tags', true)->setLabelClass('col-md-3', true);
                $form->select('jiujing_jiaodu_left.a', 'A')->placeholder('电脑验光A轴数据')->options(Config::getSelectOptionsNumber(0, 180))->config('tags', true)->setLabelClass('col-md-3', true);

                $form->select('yanguang_zonghe_right.a', 'A')->placeholder('电脑验光A轴数据')->options(Config::getSelectOptionsNumber(0, 180))->config('tags', true)->setLabelClass('col-md-3', true);
                $form->select('yanguang_zonghe_left.a', 'A')->placeholder('电脑验光A轴数据')->options(Config::getSelectOptionsNumber(0, 180))->config('tags', true)->setLabelClass('col-md-3', true);
            });
            $form->column(6, function (Form $form) {
                $form->selecttwo('yanzhu_right', '眼轴（右）')->options(Config::getSelectOptionsNumber(20, 28))->options1(Config::getSelectOptionsNumber(1, 99, true))->setLabelClass('col-md-4', true);
                $form->select('qulv_right', '曲率（右）')->options(Config::getSelectOptionsNumber(39, 47))->setLabelClass('col-md-4', true)->config('tags', true)->setLabelClass('col-md-4', true)->help('D');
                $form->select('yanwei_right', '眼位（右）')->options(Config::getSelectOptionsNumber(0, 30))->setLabelClass('col-md-4', true)->config('tags', true)->setLabelClass('col-md-4', true)->help('△');
                $form->radio('yandi_right', '眼底（右）')->options(Config::selectOptions(pid: 539))->setLabelClass('col-md-4', true);
                $form->radio('sejue_right', '色觉功能（右）')->options(Config::selectOptions(pid: 479))->setLabelClass('col-md-4', true);
                $form->text('duibidu_right', '对比敏感度（右）')->setLabelClass('col-md-4', true);
            });
            $form->column(6, function (Form $form) {
                $form->selecttwo('yanzhu_left', '左')->options(Config::getSelectOptionsNumber(20, 28))->options1(Config::getSelectOptionsNumber(1, 99, true))->setLabelClass('col-md-1', true);
                $form->select('qulv_left', '左')->options(Config::getSelectOptionsNumber(39, 47))->config('tags', true)->setLabelClass('col-md-2', true)->help('D');
                $form->select('yanwei_left', '左')->options(Config::getSelectOptionsNumber(0, 30))->config('tags', true)->setLabelClass('col-md-2', true)->help('△');
                $form->radio('yandi_left', '左')->options(Config::selectOptions(pid: 539));
                $form->radio('sejue_left', '左')->options(Config::selectOptions(pid: 479));
                $form->text('duibidu_left', '左');
            });
            
            

                $form->column(6, function (Form $form) {
                    $form->select('shuangyan_liti_right', '立体视功能(右)')->options(Config::selectOptions(pid: 542))->setLabelClass('col-md-4', true);
                    $form->select('shuangyan_zhengxiang_right', '正相对调节(右)')->options(Config::selectOptions(pid: 548))->setLabelClass('col-md-4', true);
                    $form->select('shuangyan_fuxiang_right', '负相对调节(右)')->options(Config::selectOptions(pid: 553))->setLabelClass('col-md-4', true);
                    $form->select('shuangyan_lingmindu_right', 'Flipper(调节灵敏度)(右)')->options(Config::getSelectOptionsNumber(0.5, 50, false, 0.5))->setLabelClass('col-md-4', true);
                    $form->select('shuangyan_tiaojie_right', 'AMP调节幅度(右)')->options(Config::selectOptions(pid: 558))->setLabelClass('col-md-4', true);
                    $form->select('shuangyan_jusan_right', 'CPM（聚散灵敏度）(右)')->options(Config::getSelectOptionsNumber(0.5, 50, false, 0.5))->setLabelClass('col-md-4', true);
                });
                $form->column(6, function (Form $form) {
                    $form->select('shuangyan_liti_left', '左')->options(Config::selectOptions(pid: 542));
                    $form->select('shuangyan_zhengxiang_left', '左')->options(Config::selectOptions(pid: 548));
                    $form->select('shuangyan_fuxiang_left', '左')->options(Config::selectOptions(pid: 553));
                    $form->select('shuangyan_lingmindu_left', '左')->options(Config::getSelectOptionsNumber(0.5, 50, false, 0.5));
                    $form->select('shuangyan_tiaojie_left', '左')->options(Config::selectOptions(pid: 558));
                    $form->select('shuangyan_jusan_left', '左')->options(Config::getSelectOptionsNumber(0.5, 50, false, 0.5));
                });
            $form->column(12, function (Form $form) {
                $form->dividetitle('1、光学矫正方案');
                $form->checkbox('fangan_jiaozheng', '')->options(Config::selectOptions(pid: 447));
                $form->dividetitle('2、视觉训练方案');
                $form->checkbox('fangan_xunlian', '')->options(Config::selectOptions(pid: 454));
                $form->text('fangan_other', '其他');
                $form->dividetitle('3、行为干预强化');
                $form->checkbox('ganyu', '')->options(Config::selectOptions(pid: 464));
                $form->date('fu_check_date');
            });

            $form->saving(function(Form $form){
                $form->yanzhu_left = $form->yanzhu_left . '.' . $form->yanzhu_left_1;
                $form->yanzhu_right = $form->yanzhu_right . '.' . $form->yanzhu_right_1;
                // dd( $form->yanzhu_right);
            });

            

        });
    }
}
